/*
 * This file is part of Euphrat.
 *
 * Copyright © 2012 Bart Verhoeven
 *
 * Euphrat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Euphrat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Euphrat. If not, see <http://www.gnu.org/licenses/>.
 */
package org.euphrat.client.model;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * A change to an {@link Observable}.
 *
 * @author Bart Verhoeven
 */
public class ObservableChange {

  private final Observable source;
  private final String property;
  private final Object oldValue;
  private final Object newValue;

  /**
   * Creates a new observable change.
   *
   * @param source the object that changed
   * @param property the property that changed
   * @param oldValue the old property value
   * @param newValue the new property value
   * @throws NullPointerException source or property is {@code null}
   * @throws IllegalArgumentException property is empty
   */
  public ObservableChange(Observable source,
                          String property,
                          Object oldValue,
                          Object newValue) {

    checkNotNull(source, "source is null");
    checkNotNull(property, "property is null");
    checkArgument(!property.trim().isEmpty(), "property is empty");

    this.source = source;
    this.property = property;
    this.oldValue = oldValue;
    this.newValue = newValue;
  }

  /**
   * Returns the object that changed.
   *
   * @return the object that changed
   */
  public Observable getSource() {
    return source;
  }

  /**
   * Returns the property that changed.
   *
   * @return the property that changed
   */
  public String getProperty() {
    return property;
  }

  /**
   * Returns the old value of the property.
   *
   * @return the old property value
   */
  public Object getOldValue() {
    return oldValue;
  }

  /**
   * Returns the new value of the property.
   *
   * @return the new property value
   */
  public Object getNewValue() {
    return newValue;
  }
}
